/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmTransaccion.java
 *
 * Created on 30/11/2009, 03:18:18 AM
 */

package GUI.Auditoria;

import BusinessEntity.*;
import BusinessLogic.*;
import java.util.List;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Bernabe Yanac
 */
public class frmTransaccion extends javax.swing.JFrame {

    /** Creates new form frmTransaccion */
    private String Mensaje= "";
    public frmTransaccion() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlTransacciones = new javax.swing.JPanel();
        lblNombre = new javax.swing.JLabel();
        lblUsuario = new javax.swing.JLabel();
        lblAccion = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        txtUsuario = new javax.swing.JTextField();
        cmbAccion = new javax.swing.JComboBox();
        pnlResultado = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tlbTransaccion = new javax.swing.JTable();
        btnCerrar = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        btnBuscar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Transaccion");
        setName("Transacciones"); // NOI18N
        setResizable(false);

        pnlTransacciones.setBorder(javax.swing.BorderFactory.createTitledBorder("Parametro de Busqueda de Transacciones"));

        lblNombre.setText("Cod Log: ");

        lblUsuario.setText("Usuario : ");

        lblAccion.setText("Accion : ");

        cmbAccion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<Seleccione>", "Registrar", "Modificar", "Eliminar" }));

        javax.swing.GroupLayout pnlTransaccionesLayout = new javax.swing.GroupLayout(pnlTransacciones);
        pnlTransacciones.setLayout(pnlTransaccionesLayout);
        pnlTransaccionesLayout.setHorizontalGroup(
            pnlTransaccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlTransaccionesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlTransaccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNombre)
                    .addComponent(lblUsuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlTransaccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlTransaccionesLayout.createSequentialGroup()
                        .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(79, 79, 79)
                        .addComponent(lblAccion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cmbAccion, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        pnlTransaccionesLayout.setVerticalGroup(
            pnlTransaccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlTransaccionesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlTransaccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombre)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAccion)
                    .addComponent(cmbAccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlTransaccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblUsuario))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlResultado.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultado de la Busqueda"));

        tlbTransaccion.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Cod", "Usuario", "Accion", "Modulo", "IP", "Fecha"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tlbTransaccion);
        tlbTransaccion.getColumnModel().getColumn(0).setResizable(false);
        tlbTransaccion.getColumnModel().getColumn(0).setPreferredWidth(50);
        tlbTransaccion.getColumnModel().getColumn(1).setResizable(false);
        tlbTransaccion.getColumnModel().getColumn(1).setPreferredWidth(200);
        tlbTransaccion.getColumnModel().getColumn(2).setResizable(false);
        tlbTransaccion.getColumnModel().getColumn(2).setPreferredWidth(200);
        tlbTransaccion.getColumnModel().getColumn(3).setResizable(false);
        tlbTransaccion.getColumnModel().getColumn(3).setPreferredWidth(200);
        tlbTransaccion.getColumnModel().getColumn(4).setResizable(false);
        tlbTransaccion.getColumnModel().getColumn(4).setPreferredWidth(170);
        tlbTransaccion.getColumnModel().getColumn(5).setResizable(false);
        tlbTransaccion.getColumnModel().getColumn(5).setPreferredWidth(300);

        javax.swing.GroupLayout pnlResultadoLayout = new javax.swing.GroupLayout(pnlResultado);
        pnlResultado.setLayout(pnlResultadoLayout);
        pnlResultadoLayout.setHorizontalGroup(
            pnlResultadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlResultadoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 589, Short.MAX_VALUE))
        );
        pnlResultadoLayout.setVerticalGroup(
            pnlResultadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlResultadoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Cancelar.png"))); // NOI18N
        btnCerrar.setText("Cancelar");
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Limpiar.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");

        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/BuscarComputadora.png"))); // NOI18N
        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlTransacciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(129, 129, 129)
                        .addComponent(btnBuscar)
                        .addGap(18, 18, 18)
                        .addComponent(btnLimpiar)
                        .addGap(18, 18, 18)
                        .addComponent(btnCerrar))
                    .addComponent(pnlResultado, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCerrar)
                    .addComponent(btnLimpiar)
                    .addComponent(btnBuscar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnlTransacciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(pnlResultado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btnCerrarActionPerformed
   private void llenarTabla(){
         List<TransaccionBE> lstTransaccionBE;
        TransaccionBL objTransaccionBL = new TransaccionBL();
        TransaccionBE objTransaccionAuxBE = new TransaccionBE();
        UsuarioBE objUsuarioAuxBE = new UsuarioBE();
        objUsuarioAuxBE.setUsuario(this.txtUsuario.getText().toString());
        //objTransaccionAuxBE.setObjUsuarioBE(objUsuarioAuxBE);
        String CodLog ="";
        CodLog = (this.txtCodigo.getText().toString());

        LogUsuarioBE objLogUsuarioAuxBE = new LogUsuarioBE();
        objTransaccionAuxBE.setObjLogUsuarioBE(objLogUsuarioAuxBE);
                 lstTransaccionBE = objTransaccionBL.buscarTransaccion(objTransaccionAuxBE);
            // llenar la tabla
            if (!lstTransaccionBE.isEmpty()){
                DefaultTableModel model = (DefaultTableModel) this.tlbTransaccion.getModel();
                model.setRowCount(0) ;

                for (TransaccionBE obj : lstTransaccionBE){
                       Object[] newRow = {
//                       obj.getCodlog(),
//                       obj.getObjUsuarioBE().getUsuario(),
//                       obj.getAccion(),
//                       obj.getConsultaRealizada(),
//                       obj.getObjLogUsuarioBE().getIP(),
                       obj.getFecha()};
                       model.addRow(newRow);
                }
                this.tlbTransaccion.setModel(model);
                Mensaje = "Búsqueda satisfactoria.";
            }
            else{
                Mensaje = "No se encontró información que mostrar.";
        }
 }

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        // TODO add your handling code here:
        llenarTabla();
    }//GEN-LAST:event_btnBuscarActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmTransaccion().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JComboBox cmbAccion;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAccion;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblUsuario;
    private javax.swing.JPanel pnlResultado;
    private javax.swing.JPanel pnlTransacciones;
    private javax.swing.JTable tlbTransaccion;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables

}
